# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lwan
pkgver=0.1
pkgrel=1
pkgdesc="Experimental, scalable, high performance HTTP server"
url="https://lwan.ws"
arch="x86_64"
license="GPL-2.0-or-later"
checkdepends="python3 py3-requests"
makedepends="cmake bsd-compat-headers lua5.1-dev zlib-dev"
subpackages="$pkgname-dev $pkgname-libs $pkgname-dbg"
source="$pkgname-$pkgver.tar.gz::https://github.com/lpereira/lwan/archive/v$pkgver.tar.gz
	fix-pthread-stack-min.patch
	fix-libdir.patch
	fix-pkgconfig-version.patch
	"

build() {
	CFLAGS="$CFLAGS -DHAS_SECURE_GETENV=1"
	VERSION="$pkgver" \
	cmake -B build \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=ON
	make -C build
}

check() {
	make -C build testsuite -j1
}

package() {
	make -C build DESTDIR="$pkgdir" install
	rm -f "$pkgdir"/usr/lib/*.a
}

libs() {
	default_libs

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/*.so "$subpkgdir"/usr/lib/
}

dev() {
	depends_dev="$pkgname=$pkgver-r$pkgrel"
	default_dev
}

sha512sums="6cd42b81402f98c13f905149e515758994b15d9bda6179112c5b2ce59f63c1ce6299234ffcdd64fbc8c37e5f4fd45cfe125c80a05a09ba599158ecf26f5c511c  lwan-0.1.tar.gz
e0db0c8c580543399893a86374cc2597cd8f8b358bc79334401948f0729e6da69d719388f023fd696e71d4cca3d9312d26b62b5d8aa0d44196754f8707b0bbcb  fix-pthread-stack-min.patch
43e3cdbfa55357a35ea3980d18dcd1962bb850b52592f8c5d270f5f4860cde3ab1e4e371136cb59b7b3d1fa98d81c0f5de447630b40d2300953ff6b62ab1bb4a  fix-libdir.patch
b1107bcca58a6243a1e297ec86af7a5fddde856ef718425903abb6163295f6f861c7c55ec961118f087e175b23d2772cf3ce25b998bca8da3129c289ab10ad65  fix-pkgconfig-version.patch"
